//
//  PicViewController.m
//  20170207
//
//  Created by xuPeng on 2017/9/20.
//  Copyright © 2017年 一直丶黑曼巴. All rights reserved.
//
#import "Header.h"
#import "PicViewController.h"
#import "FriendModelViewController.h"

@interface PicViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,copy)NSArray *titleArray;
@property (nonatomic,strong)UITableView *tableView;
@end
@implementation PicViewController
- (NSArray *)titleArray{
    if (!_titleArray) {
        _titleArray = @[@"九宫格模式",@"聊天模式",@"网页模式"];
    }
    return _titleArray;
}
- (UITableView *)tableView{
    if (!_tableView) { // 如果用self.tableView,会调用属性的setter方法，会导致setter方法的训话调用
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, PW, PH) style:UITableViewStyleGrouped];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"图片预览模式";
    [self.view addSubview:self.tableView];
}


#pragma 表视图的协议方法和数据源
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.titleArray.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellName = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
    }
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, 10, PW-40, 60)];
//    view.center = cell.center;
    view.backgroundColor = [UIColor orangeColor];
    view.layer.masksToBounds = YES;
    view.layer.cornerRadius = 9.0;
    
    UILabel *lab = [[UILabel alloc] init];
    lab.text = _titleArray[indexPath.row];
    
    lab.frame = CGRectMake(0, 0, 200, 60);
    lab.center = cell.center;
    lab.textAlignment = NSTextAlignmentCenter;
    [view addSubview:lab];

    [cell.contentView addSubview:view];
    cell.contentView.backgroundColor = [UIColor clearColor];
    cell.backgroundColor = [UIColor clearColor];
    
    // 取消cell的选中时变灰的效果
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        NSLog(@"%@",_titleArray[indexPath.row]);
        FriendModelViewController *FVC = [[FriendModelViewController alloc] init];
        [self.navigationController pushViewController:FVC animated:NO];
    }else if (indexPath.row == 1) {
        NSLog(@"%@",_titleArray[indexPath.row]);
    }else if (indexPath.row == 2) {
        NSLog(@"%@",_titleArray[indexPath.row]);
    }
}

@end
